home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / WMODULE.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  3.7 KB  |  131 lines

  1. /**********************************************************************
  2.  * 
  3.  * WModule
  4.  *
  5.  *     A wrapper class for handling modules (EXE and DLL handles).
  6.  *     Unlike other classes, no reference counting is done.  You
  7.  *     must explicitly load and unload DLLs.  This is done so that
  8.  *     you don't accidentally unload a DLL when you don't want to.
  9.  *
  10.  *********************************************************************/
  11.  
  12. #ifndef _WMODULE_HPP_INCLUDED
  13. #define _WMODULE_HPP_INCLUDED
  14.  
  15. #ifndef _WNO_PRAGMA_PUSH
  16. #pragma pack(push,8);
  17. #pragma enum int;
  18. #endif
  19.  
  20. #ifndef _WOBJECT_HPP_INCLUDED
  21. #  include "wobject.hpp"
  22. #endif
  23. #ifndef _WSTRING_HPP_INCLUDED
  24. #  include "wstring.hpp"
  25. #endif
  26.  
  27. class WBuffer;
  28.  
  29. class WCMCLASS WModule : public WObject {
  30.     WDeclareSubclass( WModule, WObject )
  31.  
  32.     public:
  33.  
  34.         /****************************************************************
  35.          * Constructors/destructors
  36.          ****************************************************************/
  37.  
  38.         // See the Load methods below...
  39.  
  40.         WModule();
  41.         WModule( const WModuleHandle handle );
  42.         WModule( const WModule & copy );
  43.  
  44.         ~WModule();
  45.  
  46.         /****************************************************************
  47.          * Properties
  48.          ****************************************************************/
  49.  
  50.         // Name 
  51.         //
  52.         //    Returns the full path of the module. 
  53.  
  54.         WString GetName() const;
  55.  
  56.         // Handle
  57.         //
  58.         //    The system handle for the module.
  59.  
  60.         WModuleHandle GetHandle() const { return _module; }
  61.  
  62.         /****************************************************************
  63.          * Methods
  64.          ****************************************************************/
  65.  
  66.         // FindProcedure
  67.         //
  68.         //    Return the address of an exported procedure.
  69.  
  70.         void *FindProcedure( const WChar *name ) const;
  71.  
  72.         // Load
  73.         //
  74.         //    Load a DLL by the given name, or attach to an already
  75.         //    loaded DLL.
  76.  
  77.         WBool Load( const WChar *path=NULL,
  78.                     WBool loadLibraryAsDataOnly=FALSE );
  79.         WBool Load( const WModuleHandle handle );
  80.         WBool Load( const WModule & copy );
  81.  
  82.         // LoadResourceData
  83.         //
  84.         //    Load the data for a resource and store it in the
  85.         //    give WBuffer.  Returns TRUE if the resource was
  86.         //    found and loaded.
  87.  
  88.         WBool LoadResourceData( const WResourceID & id, WBuffer *buf ) const;
  89.  
  90.         // Unload
  91.         //
  92.         //    Unload the DLL.
  93.  
  94.         WBool Unload();
  95.  
  96.         /****************************************************************
  97.          * Static Methods
  98.          ****************************************************************/
  99.  
  100.         // FindHandle
  101.         //
  102.         //    Returns the module handle of an already-loaded DLL.
  103.         //    Returns NULLHMODULE if the DLL is not loaded into
  104.         //    the current process.
  105.  
  106.         static WModuleHandle FindHandle( const WChar *path );
  107.  
  108.         /****************************************************************
  109.          * Operators
  110.          ****************************************************************/
  111.  
  112.         WModule& operator=( const WModule & copy );
  113.         WModule& operator=( const WModuleHandle & handle );
  114.  
  115.         int operator==( const WModule & other );
  116.  
  117.         int operator!=( const WModule & other );
  118.  
  119.         operator WModuleHandle() const { return _module; }
  120.  
  121.     private:
  122.         WModuleHandle _module;
  123. };
  124.  
  125. #ifndef _WNO_PRAGMA_PUSH
  126. #pragma enum pop;
  127. #pragma pack(pop);
  128. #endif
  129.  
  130. #endif // _WMODULE_HPP_INCLUDED
  131.